package com.ceres.device.dao;


import com.ceres.device.entity.QueryPageBean;
import com.ceres.device.pojo.Device;
import com.ceres.entity.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

@Repository
public interface DeviceMapper extends Mapper<Device> {
    /**
     *    智能设备的添加
     */
    @Insert("insert into t_device values(#{id},#{code},#{name},#{type},#{price},#{brand},#{model},#{scenarios},#{infoId},#{device_indexId},#{state})")
    int deviceAdd(Device device);

    /**
     *   查询所有的智能设备的基本信息
     * @return
     */
    @Select("select * from t_device")
    List<Device>select2All();

    /**.
     *   根据设备的Id返回设备的状态码
     */
    @Select("select state from t_device where id=#{id}")
    int select2State(Integer id);



    //@Select("select code,name,type,price,brand,model,scenarios,state from t_device where id=#{id}")
    //Device select3All(Integer id);


    /**
     *  根据id 查询单个智能设备
     */
    @Select("select * from t_device where id=#{id}")
    Device select4All(Integer id);


    /**
     *  逻辑删除，修改智能设备的状态
     */
    @Update("update t_device set state=#{state} where id=#{id}")
    int updateByState(Device device);

    /**
     *  分页查询
     * @return
     */
    @Select("select * from t_device ")
    com.github.pagehelper.Page<Device> select5all();

    /**
     *  分页查询（条件查询）
     */
    @Select("<script>select * from t_device <if test=\"queryString!=null and queryString!=''\">where code=#{queryString} or name=#{queryString}</if></script>")
    com.github.pagehelper.Page<Device> select6all(@Param("queryString") String queryString);

}


